The Flags Module¶
Customising a Transfer¶
remotemanager
comes with a Flags
module which is used internally to handle command line flags. It is used in the Transport
modules, and can help you adjust your file transfers as needed.
Lets set up a dataset and query its transport class to see this in a real world situation:
[1]:
from remotemanager import Dataset
def f():
return
dataset = Dataset(function = f,
local_dir = 'temp_local',
remote_dir = 'temp_remote',
skip=False)
[2]:
print(dataset.transport.__class__)
print('Transport commandline flags are:', dataset.transport.flags)
<class 'remotemanager.transport.rsync.rsync'>
Transport commandline flags are: -auvh --checksum
Here we can see that by default, the dataset creates an rsync
transport with the default flags auv
. Lets say that we want to change the flags to make rsync operate quietly. We need to swap the v
with a q
. If the flags are simple, or want to set them statically, you can set them:
[3]:
dataset.transport.flags = 'auq'
print('Transport commandline flags are:', dataset.transport.flags)
Transport commandline flags are: -auq
Though if you’re in a situation where they could differ, you can also modify them in place:
[4]:
dataset.transport.flags = 'auv' # reset the flags for this test
dataset.transport.flags -= 'v'
dataset.transport.flags += 'q'
print('Transport commandline flags are:', dataset.transport.flags)
Transport commandline flags are: -auq
Flags also handles verbose arguments (ones preceeded by --
), and prints them as expected:
[5]:
dataset.transport.flags += '--checksum --progress --test'
print('Transport commandline flags are:', dataset.transport.flags)
Transport commandline flags are: -auq --checksum --progress --test
We can also do the same inplace modification here, just be sure to prefix with --
:
[6]:
dataset.transport.flags -= '--test'
print('Transport commandline flags are:', dataset.transport.flags)
Transport commandline flags are: -auq --checksum --progress
In fact, you can also prefix any singular arguments with -
, as this is treated as a special case by the module: When assessing a string, it will count the amount of -
. If none are found, it assumes the single case.
[7]:
dataset.transport.flags += '-v'
print('Transport commandline flags are:', dataset.transport.flags)
Transport commandline flags are: -auqv --checksum --progress
Direct Setting¶
It is also possible to set the flags directly when importing. You can see more information on this at the Changing Transport tutorial